package com.huaxinkaiye.activity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.android.volley.toolbox.NetworkImageView;
import com.google.gson.Gson;
import com.huaxinkaiye.R;
import com.huaxinkaiye.application.HuaXinApplication;
import com.huaxinkaiye.bean.PictureInfo;
import com.huaxinkaiye.bean.PictureRows;
import com.huaxinkaiye.bean.RowsBean;
import com.huaxinkaiye.lookbigphoto.PhotosDialog;
import com.huaxinkaiye.utils.FileImageUpload;
import com.huaxinkaiye.utils.ImageUtils;
import com.huaxinkaiye.utils.OptionsUtil;
import com.huaxinkaiye.utils.PhotoImplActivity;
import com.huaxinkaiye.utils.ProgressUtil;
import com.huaxinkaiye.utils.SimpleClient;
import com.huaxinkaiye.utils.ToastUtil;
import com.huaxinkaiye.utils.UrlUtils;
import com.nostra13.universalimageloader.core.ImageLoader;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.SimpleAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

public class ChuJianDengJiActivity extends PhotoImplActivity implements
		OnClickListener, OnLongClickListener {
	public NetworkImageView im_che;
	private ImageView im_cancle, im_save, im_zuoqian, im_youhou, im_dajia,
			im_biaopai, im_jianzhi, im_motor;
	private TextView te_chepaihao, te_chuangjiantime, te_danganbianhao,
			te_lvquanguige, zuoqian_shili, youhou_shili, dajia_shili,
			te_xinjiu;
	private EditText ed_chepai, ed_dianchi, ed_luntai, ed_sanyuancuihuaqi,
			ed_beihzu, ed_zuoyi, ed_chemen, ed_lvquan, ed_shuixiang,
			ed_kongtiao, ed_kongtiaobeng, ed_dianji, ed_mada,
			ed_zhengchezhongliang;
	private Spinner spinner, xinjiu_spinner;
	private ArrayList<NameValuePair> params;
	public Map<String, Object> map;
	JSONArray jsonarray0;
	int valueCarStatusDiscountid;
	public ProgressUtil progress;
	private RowsBean rowsBean;
	private int zhaopianid = 0;
	private Boolean zouqian, youhou;
	private String picUrl = "";
	public String fileType;
	public String localzqBigPicPath = "";
	public String localyhBigPicPath = "";
	public String localdjBigPicPath = "";
	public String localbpBigPicPath = "";
	public String localjzBigPicPath = "";
	public String localmoBigPicPath = "";
	public String s_lvquanguige;
	public String s_xinjiu;
	Thread thread;
	Handler handler = new Handler() {
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case 0:
				jiexiXinjiuData(msg.obj.toString());
				break;
			case 1:
				jiexiData(msg.obj.toString());
				break;
			case 2:
				jiexiSubmitData(msg.obj.toString());
				break;
			case 3:
				jiexiPictureData(msg.obj.toString());
				break;
			}
		}
	};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_chujiandengji);
		progress = new ProgressUtil(this, "正在保存数据");
		initView();
	}

	protected void jiexiSubmitData(String s) {
		// TODO Auto-generated method stub
		Log.e("submit_data", s);
		try {
			JSONObject josn = new JSONObject(s);
			if (josn.getBoolean("isSuccess")) {
				Intent intent=new Intent(this,ChuJianListActivity.class);
				setResult(RESULT_OK,intent);
				finish();
				ToastUtil.show(this, josn.getString("message"));
			} else {
				ToastUtil.show(this, josn.getString("message"));
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	protected void jiexiPictureData(String string) {
		// TODO Auto-generated method stub
		Log.e("PicPath", string);
		Gson gson = new Gson();
		PictureInfo pinfo = gson.fromJson(string, PictureInfo.class);
		for (int i = 0; i < pinfo.getPictureInfo().size(); i++) {
			if (pinfo.getPictureInfo().get(i).getFileType() == 11) {
				localzqBigPicPath = UrlUtils.host
						+ pinfo.getPictureInfo().get(i).getPath();
				ImageLoader.getInstance().displayImage(localzqBigPicPath,
						im_zuoqian, OptionsUtil.optionsAvatar);
			}
			if (pinfo.getPictureInfo().get(i).getFileType() == 12) {
				localyhBigPicPath = UrlUtils.host
						+ pinfo.getPictureInfo().get(i).getPath();
				ImageLoader.getInstance().displayImage(localyhBigPicPath,
						im_youhou, OptionsUtil.optionsAvatar);
			}
			if (pinfo.getPictureInfo().get(i).getFileType() == 13) {
				localdjBigPicPath = UrlUtils.host
						+ pinfo.getPictureInfo().get(i).getPath();
				ImageLoader.getInstance().displayImage(localdjBigPicPath,
						im_dajia, OptionsUtil.optionsAvatar);
			}
			if (pinfo.getPictureInfo().get(i).getFileType() == 15) {
				localbpBigPicPath = UrlUtils.host
						+ pinfo.getPictureInfo().get(i).getPath();
				ImageLoader.getInstance().displayImage(localbpBigPicPath,
						im_biaopai, OptionsUtil.optionsAvatar);
			}
			if (pinfo.getPictureInfo().get(i).getFileType() == 16) {
				localjzBigPicPath = UrlUtils.host
						+ pinfo.getPictureInfo().get(i).getPath();
				ImageLoader.getInstance().displayImage(localjzBigPicPath,
						im_jianzhi, OptionsUtil.optionsAvatar);
			}
			if (pinfo.getPictureInfo().get(i).getFileType() == 17) {
				localmoBigPicPath = UrlUtils.host
						+ pinfo.getPictureInfo().get(i).getPath();
				ImageLoader.getInstance().displayImage(localmoBigPicPath,
						im_motor, OptionsUtil.optionsAvatar);
			}
		}
		progress.dismiss();
	}

	protected void jiexiXinjiuData(String string) {
		// TODO Auto-generated method stub
		ArrayList<Map<String, Object>> data = new ArrayList<Map<String, Object>>();
		try {
			jsonarray0 = new JSONArray(string);
			for (int i = 0; i < jsonarray0.length(); i++) {
				JSONObject json = new JSONObject(jsonarray0.get(i).toString());
				map = new HashMap<String, Object>();
				map.put("text", json.get("key").toString());
				data.add(map);
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		SimpleAdapter simpleAdapter = new SimpleAdapter(this, data,
				R.layout.spinner, new String[] { "text" },
				new int[] { R.id.textView1 });
		// 设置显示的数据
		xinjiu_spinner.setAdapter(simpleAdapter);
		// 注册事件
		xinjiu_spinner
				.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

					@Override
					public void onNothingSelected(AdapterView<?> parent) {
						Toast.makeText(getApplicationContext(), "没有改变的处理",
								Toast.LENGTH_LONG).show();
					}

					@Override
					public void onItemSelected(AdapterView<?> arg0, View arg1,
							int arg2, long arg3) {
						// TODO Auto-generated method stub
						Spinner spinner = (Spinner) arg0;
						s_xinjiu = spinner
								.getItemAtPosition(arg2)
								.toString()
								.substring(
										6,
										spinner.getItemAtPosition(arg2)
												.toString().length() - 1);
						// te_xinjiu.setText(spinner
						// .getItemAtPosition(arg2)
						// .toString()
						// .substring(
						// 6,
						// spinner.getItemAtPosition(arg2)
						// .toString().length() - 1));
					}
				});
	}

	protected void jiexiData(String s) {
		// TODO Auto-generated method stub
		try {
			JSONObject josn = new JSONObject(s);
			if (josn.getBoolean("isSuccess")) {
				submit();
				ToastUtil.show(this, josn.getString("message"));
			} else {
				ToastUtil.show(this, josn.getString("message"));
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	private void submit() {
		// TODO Auto-generated method stub
		if (HuaXinApplication.isNetWorkConnected()) {
			params = new ArrayList<NameValuePair>();
			params.add(new BasicNameValuePair("ids", rowsBean.getId() + ""));
			new Thread() {

				@Override
				public void run() {
					// TODO Auto-generated method stub
					super.run();
					try {
						String data = SimpleClient.doPost(
								UrlUtils.chujiandengjisubmit_url, params);
						Message mes = new Message();
						mes.what = 2;
						mes.obj = data;
						handler.sendMessage(mes);
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}

			}.start();
		} else {
			Toast.makeText(this, "网络异常", Toast.LENGTH_SHORT).show();
		}
	}

	private void initView() {
		// TODO Auto-generated method stub
		im_cancle = (ImageView) findViewById(R.id.im_cancle);
		im_cancle.setOnClickListener(this);
		im_save = (ImageView) findViewById(R.id.im_save);
		im_save.setOnClickListener(this);
		im_che = (NetworkImageView) findViewById(R.id.im_che);
		im_che.setOnClickListener(this);
		te_chepaihao = (TextView) findViewById(R.id.te_chepaihao);
		te_chuangjiantime = (TextView) findViewById(R.id.te_chuangjiantime);
		te_danganbianhao = (TextView) findViewById(R.id.te_danganbianhao);
		// te_lvquanguige = (TextView) findViewById(R.id.te_lvquanguige);
		ed_chepai = (EditText) findViewById(R.id.ed_chepai);
		ed_dianchi = (EditText) findViewById(R.id.ed_dianchi);
		ed_luntai = (EditText) findViewById(R.id.ed_luntai);
		// te_xinjiu = (TextView) findViewById(R.id.te_xinjiu);
		ed_sanyuancuihuaqi = (EditText) findViewById(R.id.ed_sanyuancuihuaqi);
		ed_beihzu = (EditText) findViewById(R.id.ed_beihzu);
		ed_zuoyi = (EditText) findViewById(R.id.ed_zuoyi);
		ed_chemen = (EditText) findViewById(R.id.ed_chemen);
		ed_lvquan = (EditText) findViewById(R.id.ed_lvquan);
		ed_shuixiang = (EditText) findViewById(R.id.ed_shuixiang);
		ed_kongtiao = (EditText) findViewById(R.id.ed_kongtiao);
		ed_kongtiaobeng = (EditText) findViewById(R.id.ed_kongtiaobeng);
		ed_dianji = (EditText) findViewById(R.id.ed_dianji);
		ed_mada = (EditText) findViewById(R.id.ed_mada);
		//ed_zhengchezhongliang = (EditText) findViewById(R.id.ed_zhengchezhongliang);
		im_zuoqian = (ImageView) findViewById(R.id.im_zuoqian);
		im_zuoqian.setOnClickListener(this);
		im_zuoqian.setOnLongClickListener(this);
		im_youhou = (ImageView) findViewById(R.id.im_youhou);
		im_youhou.setOnClickListener(this);
		im_youhou.setOnLongClickListener(this);
		im_dajia = (ImageView) findViewById(R.id.im_dajia);
		im_dajia.setOnClickListener(this);
		im_dajia.setOnLongClickListener(this);
		im_biaopai = (ImageView) findViewById(R.id.im_biaopai);
		im_biaopai.setOnClickListener(this);
		im_biaopai.setOnLongClickListener(this);
		im_jianzhi = (ImageView) findViewById(R.id.im_jianzhi);
		im_jianzhi.setOnClickListener(this);
		im_jianzhi.setOnLongClickListener(this);
		im_motor = (ImageView) findViewById(R.id.im_motor);
		im_motor.setOnClickListener(this);
		im_motor.setOnLongClickListener(this);
		zuoqian_shili = (TextView) findViewById(R.id.zuoqian_shili);
		youhou_shili = (TextView) findViewById(R.id.youhou_shili);
		dajia_shili = (TextView) findViewById(R.id.dajia_shili);
		spinner = (Spinner) findViewById(R.id.lq_spinner);
		xinjiu_spinner = (Spinner) findViewById(R.id.xinjiu_spinner);

		initData();
		// getPictureUrl(rowsBean.getId());
	}

	private void initData() {
		// TODO Auto-generated method stub
		rowsBean = (RowsBean) getIntent().getSerializableExtra("rowsBeanInfo");
		for (int i = 0; i < rowsBean.getPictures().size(); i++) {
			if (rowsBean.getPictures().get(i).getFileType() == 1) {
				picUrl = UrlUtils.host
						+ rowsBean.getPictures().get(i).getFilepath();
				im_che.setImageUrl(picUrl, HuaXinApplication.mImageLoader);
			}
			if (rowsBean.getPictures().get(i).getFileType() == 11) {
				localzqBigPicPath = UrlUtils.host
						+ rowsBean.getPictures().get(i).getFilepath();
				ImageLoader.getInstance().displayImage(localzqBigPicPath,
						im_zuoqian, OptionsUtil.optionsAvatar);
			}
			if (rowsBean.getPictures().get(i).getFileType() == 12) {
				localyhBigPicPath = UrlUtils.host
						+ rowsBean.getPictures().get(i).getFilepath();
				ImageLoader.getInstance().displayImage(localyhBigPicPath,
						im_youhou, OptionsUtil.optionsAvatar);
			}
			if (rowsBean.getPictures().get(i).getFileType() == 13) {
				localdjBigPicPath = UrlUtils.host
						+ rowsBean.getPictures().get(i).getFilepath();
				ImageLoader.getInstance().displayImage(localdjBigPicPath,
						im_dajia, OptionsUtil.optionsAvatar);
			}
			if (rowsBean.getPictures().get(i).getFileType() == 15) {
				localbpBigPicPath = UrlUtils.host
						+ rowsBean.getPictures().get(i).getFilepath();
				ImageLoader.getInstance().displayImage(localbpBigPicPath,
						im_biaopai, OptionsUtil.optionsAvatar);
			}
			if (rowsBean.getPictures().get(i).getFileType() == 16) {
				localjzBigPicPath = UrlUtils.host
						+ rowsBean.getPictures().get(i).getFilepath();
				ImageLoader.getInstance().displayImage(localjzBigPicPath,
						im_jianzhi, OptionsUtil.optionsAvatar);
			}
			if (rowsBean.getPictures().get(i).getFileType() == 17) {
				localmoBigPicPath = UrlUtils.host
						+ rowsBean.getPictures().get(i).getFilepath();
				ImageLoader.getInstance().displayImage(localmoBigPicPath,
						im_motor, OptionsUtil.optionsAvatar);
			}
		}
		te_chepaihao.setText("车牌号： " + rowsBean.getPlateNumber());
		te_chuangjiantime.setTag("创建时间： " + rowsBean.getCreateTime());
		te_danganbianhao.setText("档案编号： " + rowsBean.getBarCode());
		ed_chepai.setText(rowsBean.getPlateNumberCount() + "");
		ed_dianchi.setText(rowsBean.getBattery() + "");
		ed_luntai.setText(rowsBean.getTyre() + "");
		ed_sanyuancuihuaqi.setText(rowsBean.getCatalyticConverter() + "");
		ed_beihzu.setText(rowsBean.getInitialsurveyMemo() + "");
		ed_zuoyi.setText(rowsBean.getChair() + "");
		ed_chemen.setText(rowsBean.getDoorCount() + "");
		ed_lvquan.setText(rowsBean.getAluminumRing() + "");
		ed_shuixiang.setText(rowsBean.getWaterTank() + "");
		ed_kongtiao.setText(rowsBean.getAirConditioner() + "");
		ed_kongtiaobeng.setText(rowsBean.getAirConditioningPump() + "");
		ed_dianji.setText(rowsBean.getElectricalAppliances() + "");
		ed_mada.setText(rowsBean.getMotor() + "");
		//ed_zhengchezhongliang.setText(rowsBean.getWeight() + "");
		InitSpinnerData();
		InitSpinnerData2();
	}

	private void InitSpinnerData2() {
		// TODO Auto-generated method stub
		if (HuaXinApplication.isNetWorkConnected()) {
			params = new ArrayList<NameValuePair>();
			params.add(new BasicNameValuePair("", ""));
			new Thread() {

				@Override
				public void run() {
					// TODO Auto-generated method stub
					super.run();
					String data;
					try {
						data = SimpleClient.doPost(
								UrlUtils.valueCarStatusDiscount_url, params);
						Log.e("xinjiu_data", data);
						Message message = new Message();
						message.what = 0;
						message.obj = data;
						handler.sendMessage(message);
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}.start();
		} else {
			Toast.makeText(this, "网络异常", Toast.LENGTH_SHORT).show();
		}
	}

	private void InitSpinnerData() {
		// TODO Auto-generated method stub
		List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();
		Map<String, Object> map = new HashMap<String, Object>();
		// map.put("logo", R.drawable.ic_launcher);
		map.put("text", "否");

		Map<String, Object> map2 = new HashMap<String, Object>();
		// map2.put("logo", R.drawable.ic_launcher);
		map2.put("text", "是");
		Map<String, Object> map3 = new HashMap<String, Object>();
		// map2.put("logo", R.drawable.ic_launcher);
		//map3.put("text", "小");
		data.add(map);
		data.add(map2);
		//data.add(map3);

		SimpleAdapter simpleAdapter = new SimpleAdapter(this, data,
				R.layout.spinner, new String[] { "text" },
				new int[] { R.id.textView1 });
		// 设置显示的数据
		spinner.setAdapter(simpleAdapter);

		// 注册事件
		spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

			@Override
			public void onNothingSelected(AdapterView<?> parent) {
				Toast.makeText(getApplicationContext(), "没有改变的处理",
						Toast.LENGTH_LONG).show();
			}

			@Override
			public void onItemSelected(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				// TODO Auto-generated method stub
				Spinner spinner = (Spinner) arg0;
				s_lvquanguige = spinner
						.getItemAtPosition(arg2)
						.toString()
						.substring(
								6,
								spinner.getItemAtPosition(arg2).toString()
										.length() - 1)
						+ "";
				// te_lvquanguige.setText(spinner
				// .getItemAtPosition(arg2)
				// .toString()
				// .substring(
				// 6,
				// spinner.getItemAtPosition(arg2).toString()
				// .length() - 1));
				// Toast.makeText(getApplicationContext(),
				// ""+spinner.getItemAtPosition(arg2),
				// Toast.LENGTH_LONG).show();
			}

		});
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.im_cancle:
			Intent intent=new Intent(this,ChuJianListActivity.class);
			setResult(RESULT_OK,intent);
			finish();
			break;
		case R.id.im_save:
			dengJi();
			break;
		case R.id.im_che:
			if (picUrl.equals("")) {
				ToastUtil.show(this, "没有图片");
				return;
			}
			lookBigImage();
			break;
		case R.id.im_zuoqian:
			// 查看大图
			if (localzqBigPicPath.equals("")) {
				ToastUtil.show(this, "没有图片");
				return;
			}
			lookBigImage(localzqBigPicPath);
			break;
		case R.id.im_youhou:
			// 查看大图
			if (localyhBigPicPath.equals("")) {
				ToastUtil.show(this, "没有图片");
				return;
			}
			lookBigImage(localyhBigPicPath);
			break;
		case R.id.im_dajia:
			// 查看大图
			if (localdjBigPicPath.equals("")) {
				ToastUtil.show(this, "没有图片");
				return;
			}
			lookBigImage(localdjBigPicPath);
			break;

		case R.id.im_biaopai:
			// 查看大图
			if (localbpBigPicPath.equals("")) {
				ToastUtil.show(this, "没有图片");
				return;
			}
			lookBigImage(localbpBigPicPath);
			break;
		case R.id.im_jianzhi:
			// 查看大图
			if (localjzBigPicPath.equals("")) {
				ToastUtil.show(this, "没有图片");
				return;
			}
			lookBigImage(localjzBigPicPath);
			break;
		case R.id.im_motor:
			// 查看大图
			if (localmoBigPicPath.equals("")) {
				ToastUtil.show(this, "没有图片");
				return;
			}
			lookBigImage(localmoBigPicPath);
			break;
		}
	}

	private void dengJi() {
		// TODO Auto-generated method stub
		if (HuaXinApplication.isNetWorkConnected()) {
			if (localzqBigPicPath.equals("")) {
				ToastUtil.show(this, "请上传左前图片");
				return;
			}
			if (localyhBigPicPath.equals("")) {
				ToastUtil.show(this, "请上传右后图片");
				return;
			}
			if (localdjBigPicPath.equals("")) {
				ToastUtil.show(this, "请上传大架图片");
				return;
			}
			if (ed_chepai.getText().toString().equals("")) {
				ToastUtil.show(this, "车牌数不为空");
				return;
			}
			if (ed_dianchi.getText().toString().equals("")) {
				ToastUtil.show(this, "电池数不为空");
				return;
			}
			if (ed_luntai.getText().toString().equals("")) {
				ToastUtil.show(this, "轮胎数不为空");
				return;
			}
			if (ed_sanyuancuihuaqi.getText().toString().equals("")) {
				ToastUtil.show(this, "三元催化器数不为空");
				return;
			}
			if (ed_zuoyi.getText().toString().equals("")) {
				ToastUtil.show(this, "座椅数不为空");
				return;
			}
			if (ed_chemen.getText().toString().equals("")) {
				ToastUtil.show(this, "车门数不为空");
				return;
			}
			if (ed_lvquan.getText().toString().equals("")) {
				ToastUtil.show(this, "铝圈数不为空");
				return;
			}
			if (ed_shuixiang.getText().toString().equals("")) {
				ToastUtil.show(this, "水箱数不为空");
				return;
			}
			if (ed_kongtiao.getText().toString().equals("")) {
				ToastUtil.show(this, "空调数不为空");
				return;
			}
			if (ed_kongtiaobeng.getText().toString().equals("")) {
				ToastUtil.show(this, "空调泵数不为空");
				return;
			}
			if (ed_dianji.getText().toString().equals("")) {
				ToastUtil.show(this, "电机数不为空");
				return;
			}
			if (ed_mada.getText().toString().equals("")) {
				ToastUtil.show(this, "马达数不为空");
				return;
			}
			// if (te_lvquanguige.getText().toString().equals("")) {
			// ToastUtil.show(this, "铝圈规格数不为空");
			// return;
			// }
//			if (!ed_zhengchezhongliang.getText().toString().equals("")) {
//				// ed_beihzu.setVisibility(View.GONE);
//				// }else{
//				if (ed_beihzu.getText().toString().equals("")) {
//					ToastUtil.show(this, "备注不为空");
//					return;
//				}
//			}
			// Log.e("chujiandengji____++", rowsBean.getId() + "----"+
			// ed_chepai.getText().toString() + "----"+
			// ed_dianchi.getText().toString() + "----"+
			// ed_zhengchezhongliang.getText().toString() + "----"+
			// ed_luntai.getText().toString() + "----"+
			// ed_sanyuancuihuaqi.getText().toString() + "----"+
			// ed_zuoyi.getText().toString() + "----"+
			// ed_lvquan.getText().toString() + "----"+
			// ed_shuixiang.getText().toString() + "----"+
			// ed_kongtiao.getText().toString() + "----"+
			// ed_kongtiaobeng.getText().toString() + "----"+
			// ed_dianji.getText().toString() + "----"+
			// ed_mada.getText().toString() + "----"+
			// te_lvquanguige.getText().toString() + "----"+
			// ed_beihzu.getText().toString()
			// );
			for (int i = 0; i < jsonarray0.length(); i++) {
				JSONObject json;
				try {
					json = new JSONObject(jsonarray0.get(i).toString());
					if (json.getString("name").equals(s_xinjiu)) {
						valueCarStatusDiscountid = json.getInt("id");
						Log.e("valueCarStatusDiscountid",
								valueCarStatusDiscountid + "");
					}
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			params = new ArrayList<NameValuePair>();
			params.add(new BasicNameValuePair("id", rowsBean.getId() + ""));
			params.add(new BasicNameValuePair("plateNumberCount", ed_chepai
					.getText().toString()));
			params.add(new BasicNameValuePair("battery", ed_dianchi.getText()
					.toString()));
//			params.add(new BasicNameValuePair("weight", ed_zhengchezhongliang
//					.getText().toString()));
			params.add(new BasicNameValuePair("tyre", ed_luntai.getText()
					.toString()));
			params.add(new BasicNameValuePair("catalyticConverter",
					ed_sanyuancuihuaqi.getText().toString()));
			params.add(new BasicNameValuePair("chair", ed_zuoyi.getText()
					.toString()));
			params.add(new BasicNameValuePair("doorCount", ed_chemen.getText()
					.toString()));
			params.add(new BasicNameValuePair("aluminumRing", ed_lvquan
					.getText().toString()));
			params.add(new BasicNameValuePair("waterTank", ed_shuixiang
					.getText().toString()));
			params.add(new BasicNameValuePair("airConditioner", ed_kongtiao
					.getText().toString()));
			params.add(new BasicNameValuePair("airConditioningPump",
					ed_kongtiaobeng.getText().toString()));
			params.add(new BasicNameValuePair("electricalAppliances", ed_dianji
					.getText().toString()));
			params.add(new BasicNameValuePair("motor", ed_mada.getText()
					.toString()));
			// params.add(new BasicNameValuePair("aluminumRingSpec",
			// te_lvquanguige.getText().toString()));
			params.add(new BasicNameValuePair("aluminumRingSpec", s_lvquanguige));
			params.add(new BasicNameValuePair("initialsurveyMemo", ed_beihzu
					.getText().toString() + ""));
			params.add(new BasicNameValuePair("valueCarStatusDiscount.id",
					valueCarStatusDiscountid + ""));
			// params.add(new BasicNameValuePair("Cookie",
			// "JSESSIONID=4ECCE1C50A0C4833776992CAB53A441E"));

			new Thread() {

				@Override
				public void run() {
					// TODO Auto-generated method stub
					super.run();
					String data;
					try {
						data = SimpleClient.doPost(
								UrlUtils.chujianlistdengji_url, params);
						Log.e("chujiandengji_data", data);
						Message mes = new Message();
						mes.what = 1;
						mes.obj = data;
						handler.sendMessage(mes);
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}

			}.start();
		} else {
			Toast.makeText(this, "网络异常", Toast.LENGTH_SHORT).show();
		}
	}

	@Override
	public void doAfterZoom(final Bitmap bitmap) {
		// TODO Auto-generated method stub	
		if (zhaopianid == 11) {
			im_zuoqian.setImageBitmap(bitmap);
		} else if (zhaopianid == 12) {
			im_youhou.setImageBitmap(bitmap);
		} else if (zhaopianid == 13) {
			im_dajia.setImageBitmap(bitmap);
		} else if (zhaopianid == 15) {
			im_biaopai.setImageBitmap(bitmap);
		} else if (zhaopianid == 16) {
			im_jianzhi.setImageBitmap(bitmap);
		} else if (zhaopianid == 17) {
			im_motor.setImageBitmap(bitmap);
		}
		String localPicPath = ImageUtils.savePicToCache(
				ChuJianDengJiActivity.this, bitmap);
		Log.e("localPicPath------", localPicPath);
		params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("id", rowsBean.getId() + ""));
		params.add(new BasicNameValuePair("fileType", zhaopianid + ""));
		params.add(new BasicNameValuePair("pictureFile", localPicPath));
		final String url = UrlUtils.picture_url;
		if (HuaXinApplication.isNetWorkConnected()) {
			progress.show();
			new Thread() {

				@Override
				public void run() {
					// TODO Auto-generated method stub
					super.run();
					String result = FileImageUpload.postFile(url, params);
					Log.e("uploadPicture_result", result);
					Message message = new Message();
					message.what = 3;
					message.obj = result;
					handler.sendMessage(message);
				}
			}.start();			
		} else {
			Toast.makeText(this, "网络异常", Toast.LENGTH_SHORT).show();
		}
	}

	@Override
	public boolean onLongClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.im_zuoqian:
			zhaopianid = 11;
			showPopupMenu(im_zuoqian, false, "other");
			break;
		case R.id.im_youhou:
			zhaopianid = 12;
			showPopupMenu(im_youhou, false, "other");
			break;
		case R.id.im_dajia:
			zhaopianid = 13;
			showPopupMenu(im_dajia, false, "other");
			break;
		case R.id.im_biaopai:
			zhaopianid = 15;
			showPopupMenu(im_biaopai, false, "other");
			break;
		case R.id.im_jianzhi:
			zhaopianid = 16;
			showPopupMenu(im_jianzhi, false, "other");
			break;
		case R.id.im_motor:
			zhaopianid = 17;
			showPopupMenu(im_motor, false, "other");
			break;
		}
		return true;
	}

	// public void getPictureUrl(int carid) {
	// // TODO Auto-generated method stub
	// final List<NameValuePair> params = new ArrayList<NameValuePair>();
	// params.add(new BasicNameValuePair("cid", carid+""));
	// new Thread(){
	//
	// @Override
	// public void run() {
	// // TODO Auto-generated method stub
	// super.run();
	// try {
	// String data = SimpleClient.doPost(
	// UrlUtils.picturelist_url, params);
	// Gson gson=new Gson();
	// PictureRows pr=gson.fromJson(data, PictureRows.class);
	// Message message = new Message();
	// message.what = 3;
	// message.obj = UrlUtils.host+pr.getRows().get(0).getFilepath();
	// handler.sendMessage(message);
	// } catch (Exception e) {
	// // TODO Auto-generated catch block
	// e.printStackTrace();
	// }
	// }
	// }.start();
	// }
	protected void lookBigImage() {
		// TODO Auto-generated method stub
		final ArrayList<String> urllist = new ArrayList<String>();
		urllist.add(picUrl);
		new PhotosDialog(ChuJianDengJiActivity.this, R.style.Dialog).show(0,
				urllist);
	}

	protected void lookBigImage(String s) {
		// TODO Auto-generated method stub
		final ArrayList<String> urllist = new ArrayList<String>();
		urllist.add(s);
		new PhotosDialog(ChuJianDengJiActivity.this, R.style.Dialog).show(0,
				urllist);
	}
}
